# 定义类
import requests

from api.p2p_reg_login import RegLogin
from config import BASE_URL


# 定义充值接口类
class ApproveTrust(object):

    # 定义实例属性
    def __init__(self, session):
        self.__session = session
        self.__approve_url = BASE_URL + "/member/realname/approverealname"
        self.__get_approve_url = BASE_URL + "/member/member/getapprove"
        self.__trust_url = BASE_URL + "/trust/trust/register"
        self.__img_url = BASE_URL + "/common/public/verifycode/{}"
        self.__recharge_url = BASE_URL + "/trust/trust/recharge"

    # 定义接口方法
    def approve(self, data1):
        # data = {"realname": "瑞文", "card_id": "150422199003077251"}
        file = {"a": "b"}
        res = self.__session.post(url=self.__approve_url, files=file, data=data1)
        return res

    def get_approve(self):
        return self.__session.post(url=self.__get_approve_url)

    def trust(self):
        return self.__session.post(url=self.__trust_url)

    def get_recharge_img(self, num):
        return self.__session.get(url=self.__img_url.format(num))

    def recharge(self, reqdata):
        return self.__session.post(url=self.__recharge_url, data=reqdata)


if __name__ == '__main__':
    # 创建对象
    session = requests.Session()
    reg_login = RegLogin(session)
    app_trust = ApproveTrust(session)
    # 调用方法：前置登录成功
    data1 = {"keywords": "13900005001", "password": "Aa123456"}
    reg_login.login(data1)
    # 调用实名方法
    data = {"realname": "瑞文", "card_id": "530802199403075893"}
    res = app_trust.approve(data)

    print(res.json())
